package cn.dcpnet.controller;

import cn.dcpnet.client.TestFeign;
import cn.dcpnet.pojo.RequestDto;
import cn.dcpnet.pojo.ResponseDto;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * <h1>类名称</h1>
 *
 * <p>
 * 类描述
 * </p>
 *
 * @author Dcpnet
 * @since 2025/1/2 22:31
 **/
@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private TestFeign testFeign;

    @RequestMapping("/invoke")
    public ResponseDto<Map<String, Object>> invoke() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("id", UUID.randomUUID().toString().replaceAll("-", ""));
        map.put("code", 200);
        map.put("message", "请求成功");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        map.put("data", sdf.format(new Date()));
        return new ResponseDto<Map<String, Object>>("123", map);
    }

    @RequestMapping("/feign")
    public ResponseDto<Map<String, Object>> feign() {
        RequestDto<String> requestDto = new RequestDto<String>(UUID.randomUUID().toString(), "呵呵");
        ResponseDto<Map<String, Object>> responseDto = testFeign.testInvoke("1", "1", requestDto);
        return responseDto;
    }
}
